<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>外派业务管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_33" >
                    <div class="label">创建时间</div>
                    <div class="field">
                        <input name="stDt" id="stDt" type="text" class="ui-datepicker" value="">
                        <span>---</span>
                        <input name="endDt" id="endDt" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">创建人</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">风险隐患</div>
                    <div class="field">
                        <select name="hidRisk"  id="hidRisk" >
                            <option value="" selected="selected">请选择</option>
                            <c:forEach items="${hidRiskList}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                </div>
                <div class="clearFix"></div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<div id="change_Html" style="display:none">
    <form id="change_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100_auto">
                <div class="label">实际供应商名称</div>
                <div class="field">
                    <input name="realSplNm" id="realSplNm" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">实际联系方式</div>
                <div class="field">
                    <input name="realTel" id="realTel" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveChange_Btn" class="sq-button sq-button-round" onclick="addRealSplNm();">保存</span>
            <input name="id" id="id" type="hidden" class="ui-textbox" value="">
        </div>
    </form>
</div>

<div id="see_Html" style="display:none">
<form id="see_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100_auto">
            <div class="label">实际供应商名称</div>
            <div class="field">
                <input name="realSplNm" id="realSplNmSee" type="text" class="ui-textbox" value="" ligerui="width:250" readonly>
            </div>
        </div>
        <div class="fieldBox col_100_auto">
            <div class="label">实际联系方式</div>
            <div class="field">
                <input name="realTel" id="realTelSee" type="text" class="ui-textbox" value="" ligerui="width:250" readonly>
            </div>
        </div>
    </div>
    <div class="btnsBox">
        <span id="closeBtn" class="sq-button sq-button-round">我知道了，关闭</span>
        <input name="id" id="idSee" type="hidden" class="ui-textbox" value="">
    </div>
</form>
</div>

<script type="text/javascript">
    var grid = null, form = null;
    $(function () {
        initGrid();
        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
            //detailGrid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

    });

    /* 初始化列表*/
    function initGrid(){
        var url = '<%=path%>/project/prjbscinfo/initExpBusinessList.do';
        grid = $("#ligergrid1").ligerGrid({
                url:url,
                method: 'get',
                columns: [
                    {display: '风险隐患', name: 'hidRisk', width: 150, align: 'center',
                        render: function (rowdata, rowindex, value, column) {
                            var h = '';
                            if(value&&value!="null"){
                                h+='<div style="color:red">' + value + '</div>';
                            }else {
                                h+='——';
                            }
                            return h;
                        },
                        enabledSort: true},
                    {display: '项目名称', name: 'prjNm', align:'left',minWidth: 140 ,
                        render: function (rowdata, rowindex, value, column) {
                            var h = '';
                            if(value&&value!="null"){
                                h+='<a href="javascript:prjDetailBtn(';
                                h+="'"+rowdata.id+"',";
                                h+=')">'+value+'</a>'
                            }
                            return h;
                        },
                        enabledSort:true},
                    {display: '合同号', name: 'lsCntNo', minWidth: 140 , enabledSort:true},
                    {display: '客户', name: 'cstNm', minWidth: 100,align:'center', enabledSort:true},
                    {display: '创建人', name: 'cstMgrNm', minWidth: 100,align:'center', enabledSort:true},
                    {display: '家访人', name: 'homeVisitNm', minWidth: 100,align:'center', enabledSort:true},
                    {display: '家访时间', name: 'homeVisitEndDt', minWidth: 100 , render:renderDate, enabledSort:true},
                    {display: '项目类型', name: 'prjTypCdNm', width: 140, enabledSort:true},
                    {display: '申请单号', name: 'pNo', minWidth: 140 ,
                        render: function (rowdata, rowindex, value, column) {
                            var h = '';
                            if(value&&value!="null"){
                                if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_CAR){
                                    h+='<a href="javascript:commShowFlowForCarBiz(';
                                }else if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC){
                                    if(StringUtils.isNotEmpty(rowdata.cstMgrOrgCd)){
                                        var orgCd = rowdata.cstMgrOrgCd;
                                        var orgCd_1 = orgCd.substring(0,12);
                                        if(orgCd_1=='000000080002'){//专车客车
                                            h+='<a href="javascript:commShowFlowForBusKCBiz(';
                                        }else{
                                            h+='<a href="javascript:commShowFlowForBusBiz(';
                                        }
                                    }else{
                                        h+='<a href="javascript:commShowFlowForBusBiz(';
                                    }
                                }else{
                                    if(rowdata.prjTypCd=='DSFGHKDCPSZ'){
                                        h+='<a href="javascript:commShowTempFlow(';
                                    }else{
                                        h+='<a href="javascript:commShowFlowPrj(';
                                    }
                                }
                                h+="'"+rowdata.pInstId+"',";
                                h+="'"+rowdata.prjStsCd+"',";
                                h+="'"+rowdata.id+"'";
                                h+=')">'+value+'</a>'
                            }
                            return h;
                        },
                        enabledSort:true},
                    {display: '实际供应商', name: 'realSplNm', width: 150,
                        render: function (rowdata, rowindex, value, column) {
                            var h = '';
                            if(value&&value!="null"){
                                h+='<a href="javascript:seeRealSpl(';
                                h+="'"+rowdata.id+"',";
                                h+=')">'+value+'</a>'
                            }
                            return h;
                        },
                        enabledSort:true},
                    {display: '操作',minWidth: 250,align:'left',
                        render: function (rowdata, rowindex, value){
                            var h="";
                            h+='<a class="sq-button-hasicon" href="javascript:sendSMS(';
                            h+="'"+rowdata.id+"',";
                            h+="'"+rowdata.lsCntNo+"'";
                            h+=')">短信提醒</a>'
                            h+='<a class="sq-button-hasicon" href="javascript:updataRealSpl(';
                            h+="'"+rowdata.id+"'";
                            h+=')">修改实际供应商</a>'
                            return h;
                        }
                    }
                ],
                pageSize: 10,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: '100%',
                heightDiff: -2,
                allowUnSelectRow: true,
                alternatingRow: false,
                rownumbers: false,  //显示序号
                onBeforeShowData: function () {
                    var grid = this;
                    grid.collapsedRows = [];
                },
                detail: {
                    height: 'auto',
                    onShowDetail: showMortgagorGrid
                }
            })
        grid.setHeight(100);
        form = $("#searchBar").ligerForm();
    }

    function getSearchParam(){
        form = liger.get("searchBar");
        var data = form.getData();
        return data;
    }

    /**
     * 显示项目下的抵押人信息
     */
    function showMortgagorGrid(row,detailPanel,callback){

        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        var searchParam = getSearchParam();
        contractGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/project/prjprddtl/selectExpBusTwoList.do?prjId=' + row.id,
            parms:searchParam,
            method: 'get',
            columns: [
                {display: '风险隐患', name: 'hidRisk', width: 150, align: 'center',
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if(value&&value!="null"){
                            h+='<div style="color:red">' + value + '</div>';
                        }else {
                            h+='——';
                        }
                        return h;
                    },
                    enabledSort: false},
                {display: '合同号', name: 'lsCntNo', minWidth: 140 , enabledSort:true},
                /*{display: '支付表号', name: 'paySchNo', width: 160, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showPrjPrdPaySchDtl('+rowindex+')"><span class="gridTip" title="支付表查看">'+rowdata.paySchNo+'</span></a>';
                    }
                },*/
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left', enabledSort: false},
                {display: '创建人', name: 'cstMgrNm', minWidth: 140,align:'center', enabledSort:true},
                {display: '抵押人', name: 'mortgagorNm', minWidth: 140,align:'center', enabledSort:true},
                {display: '抵押时间', name: 'mortgagorEndDt', minWidth: 100 , render:renderDate, enabledSort:true},
                {display: '流程编号', name: 'prInsNo', minWidth: 140, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if(value&&value!="null"){
                            if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_CAR){
                                if(StringUtils.isNotEmpty(rowdata.bizFlag) && rowdata.bizFlag == '2'){
                                    h+='<a href="javascript:commShowFlowForGHYW(';
                                    h+="'"+rowdata.bizFlag+"',";
                                }else{
                                    h+='<a href="javascript:commShowFlowForCarBiz(';
                                }
                            }else if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC){
                                h+='<a href="javascript:commShowFlowForSpecialCar(';
                            }else{
                                h+='<a href="javascript:commShowFlow(';
                            }
                            h+="'"+rowdata.prInsId+"',";
                            h+="'"+rowdata.audStsCd+"',";
                            h+="'"+rowdata.payId+"'";
                            h+=')">'+value+'</a>'
                        }
                        return h;
                    },
                },
                {display: '放款状态', name: 'payStsCd', width: 130, enabledSort:false},
                {display: '上牌城市', name: 'cardCity', width: 130, enabledSort:false},
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //项目详情
    function prjDetailBtn(id){
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if(StringUtils.isNotEmpty(_flag)){
            if(_flag == 'false'){
                fromPrjFlag = false;
            }
        }
        Add_navTab('tab_project_detail'+id,'项目详情','<%=path%>/project/prjbscinfo/toModifyPage.do?fromPrjFlag='+fromPrjFlag+'&&id='+id+'&&detailFlag='+detailFlag);
    }

    //立项流程
    //乘用车流程
    function commShowFlowForCarBiz(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toCarBizAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //专车客车流程
    function commShowFlowForBusKCBiz(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toBusAdditionalInfoPage.do?isBusKC=1@@isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //专车以租代购流程
    function commShowFlowForBusBiz(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toBusAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //显示流程
    function commShowTempFlow(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toTempAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //显示流程
    function commShowFlowPrj(_pInstId, _audStsCd, _businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toAdditionalInfoPage.do?isDetail=1"+"@@processInstanceId="+_pInstId+"@@projectId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //放款流程
    //显示流程
    function commShowFlow(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capPay/flow/toAdditionalInfoPage.do?version=2@@capPayId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //显示流程-汽车金融工行业务
    function commShowFlowForGHYW(_bizFlag,_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPage.do?accCtrl=1@@ctrlKey=3@@bizFlag="+_bizFlag+"@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //显示流程-汽车金融
    function commShowFlowForCarBiz(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPage.do?accCtrl=1@@ctrlKey=3@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
    //显示流程-专车事业部
    function commShowFlowForSpecialCar(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPageBySpecialCar.do?entrance=0@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //修改实际供应商
    function updataRealSpl(_id) {
        $.ligerDialog.open({
            width: 500,
            // top: 100,
            title : '修改实际供应商',
            target: $("#change_Html")
        });
        //初始化数据
        initData(_id);
        var ligerForm = $("#change_form").ligerForm({validate: true});
    }

    function addRealSplNm() {
        var data = $("#change_form").serializeArray();
        data["id"] = $("#id").val();
        var url = '<%=path%>/project/prjbscinfo/modifyRealSpl.do';
        var wait_dialog;
        $.ligerDialog.hide();
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function initData(_id){
        if(!_id)return;
        var _url = '<%=path%>/project/prjbscinfo/getById.do?id=' + _id;
        $.ajax({
            type: 'get',
            dataType:'json',
            data:{id:_id},
            url: _url,
            success:function(msg){
                if(msg.success == 1){
                    setData(msg.data);//设置数据
                }else{
                    top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
    }

    //设置页面数据
    function setData(data){
        $("#id").val(data.id);
        $("#realSplNm").val(data.realSplNm);
        $("#realTel").val(data.realTel);
        $("#idSee").val(data.id);
        $("#realSplNmSee").val(data.realSplNm);
        $("#realTelSee").val(data.realTel);
    }

    //查看实际供应商
    function seeRealSpl(_id) {
        $.ligerDialog.open({
            width: 500,
            // top: 100,
            title : '查看实际供应商',
            target: $("#see_Html")
        });
        //初始化数据
        initData(_id);
        var ligerForm = $("#see_form").ligerForm({validate: true});
    }

    $("#closeBtn").click(function(event) {
        $.ligerDialog.hide();
    });

    //短信提醒功能
    function sendSMS(_id,lsCntNo) {
        var param = _id+"&lsCntNo="+lsCntNo;
        $.ligerDialog.open({
            width:800,
            height: 260,
            title: '短信提醒',
            url: '<%=path%>/expatriate/expBizManRec/toExpBizManRecInfo.do?dataId='+param
        });
    }
</script>

</body>
</html>
